<template>
	<view class="order-box" v-if="!loadding">
		<view class="bg-white">
			<view class="section">
				<list-cell :hover="false" padding="50rpx 30rpx">
					<view class="w-100 d-flex flex-column">
						<view class="d-flex align-items-center just-content-center" v-if="detail.pay_status.value == 20">
							<view class="sort-num" v-if="detail.order_status.value == 21">待审核</view>
							<view class="sort-num" v-else>{{ detail.meal_code }}</view>
						</view>
						<view class="d-flex align-items-center just-content-center" v-if="detail.pay_status.value == 10">
							<view class="sort-num">待支付</view>
						</view>
						<view class="d-flex align-items-center just-content-center" v-if="detail.pay_status.value == 10">
							<view class="f26 pay_btn" @click="onPayOrder(detail.order_id)">付款</view>
						</view>
						<view class="d-flex align-items-center just-content-center mt20" v-if="detail.pay_status.value == 10">
							<view class="f26">剩余时间：<text class="orange">{{detail.pay_end_time}}</text></view>
						</view>
						<view class="d-flex just-content-center">
							<view class="steps d-flex flex-column" :class="{'w-80': detail.delivery_type.value == 10, 'w-100': detail.delivery_type.value == 20}">
								<view class="steps__img-column">
									<view class="steps__img-column-item">
										<image src="/static/images/order/ordered_selected.png" v-if="detail.pay_status.value == 20"></image>
										<image src="/static/images/order/ordered_selected.png" v-else></image>
									</view>
									<view class="steps__img-column-item" :class="{active: detail.delivery_status.value >= 10}">
										<image src="/static/images/order/production_selected.png" v-if="detail.delivery_status.value >= 10"></image>
										<image src="/static/images/order/production.png" v-else></image>
									</view>
									<view class="steps__img-column-item" :class="{active: detail.delivery_status.value == 20}" v-if="detail.delivery_type.value == 10">
										<image src="/static/images/order/delivery_selected.png" v-if="detail.delivery_status.value == 20"></image>
										<image src="/static/images/order/delivered.png" v-else></image>
									</view>
									<view class="steps__img-column-item" :class="{active: detail.order_status.value == 20}">
										<image src="/static/images/order/delivered_selected.png" v-if="detail.order_status.value == 20"></image>
										<image src="/static/images/order/delivered.png" v-else></image>
									</view>
								</view>
								<view class="steps__text-column">
									<view class="steps__text-column-item" :class="{active: detail.pay_status.value == 20}">
										<view class="steps__column-item-line bg-transparent"></view>
										<view class="steps__text-column-item-text">已下单</view>
										<view class="steps__column-item-line"></view>
									</view>

									<view class="steps__text-column-item" :class="{active: detail.delivery_status.value == 20}">
										<view class="steps__column-item-line"></view>
										<view class="steps__text-column-item-text">{{ detail.delivery_type.value == 10 ? '待接单' : '待取餐' }}</view>
										<view class="steps__column-item-line"></view>
									</view>
									<view v-if="detail.delivery_type.value == 10" class="steps__text-column-item" :class="{active: detail.delivery_status.value == 20}">
										<view class="steps__column-item-line"></view>
										<view class="steps__text-column-item-text">配送中</view>
										<view class="steps__column-item-line"></view>
									</view>
									<view class="steps__text-column-item" :class="{active: detail.receipt_status.value == 20}">
										<view class="steps__column-item-line"></view>
										<view class="steps__text-column-item-text">
											{{ detail.delivery_type.value == 10 ? '已送达' : '已取餐' }}
										</view>
										<view class="steps__column-item-line bg-transparent"></view>
									</view>
								</view>
							</view>
						</view>
						<!-- steps end -->
						<!-- 			<view v-if="order.status<=1" class="d-flex just-content-center align-items-center font-size-base text-color-assist mb-40">
									您前面还有 <text class="text-color-primary mr-10 ml-10">4</text> 单待制作
								</view> -->
						<!-- goods begin -->
						<view class="w-100 d-flex flex-column position-relative mt-30" style="margin-bottom: -40rpx;">
							<view class="w-100 d-flex align-items-center mb-40" v-for="(good, index) in detail.product" :key="index">
								<view class="d-flex flex-column w-60 overflow-hidden">
									<view class="font-size-lg text-color-base mb-10 text-truncate">{{ good.product_name }}</view>
									<view class="font-size-sm text-color-assist text-truncate">{{ good.product_attr }}</view>
								</view>
								<view class="d-flex w-40 align-items-center justify-content-between pl-30">
									<view class="font-size-base text-color-base">x{{ good.total_num }}</view>
									<view class="font-size-base text-color-base font-weight-bold">￥{{ good.total_pay_price }}</view>
								</view>
							</view>
						</view>
						<!-- goods end -->
					</view>
				</list-cell>
			</view>
			<view class="section">
				<!-- payment and amount begin -->
				<list-cell :hover="false" padding="50rpx 30rpx">
					<view class="w-100 d-flex flex-column">

						<view class="pay-cell" v-if="detail.packing_fee!=0">
							<view>包装费</view>
							<view class="font-weight-bold">￥{{ detail.packing_fee }}</view>
						</view>
						<view class="pay-cell">
							<view>配送费</view>
							<view class="font-weight-bold">￥{{ detail.express_price }}</view>
						</view>
						<view class="pay-cell" v-if="detail.fullreduce_money!=0">
							<view>{{detail.fullreduce_remark}}</view>
							<view class="font-weight-bold">￥{{ detail.fullreduce_money }}</view>
						</view>
						<view class="pay-cell" v-if="detail.coupon_money!=0">
							<view>优惠券</view>
							<view class="font-weight-bold red">￥{{ detail.coupon_money }}</view>
						</view>
						<view class="pay-cell">
							<view>支付方式</view>
							<view class="font-weight-bold">{{ detail.pay_type.text }}</view>
						</view>
						<view class="pay-cell">
							<view>金额总计</view>
							<view class="font-weight-bold">￥{{ detail.pay_price?detail.pay_price:'' }}</view>
						</view>
					</view>
				</list-cell>
				<!-- payment and amount end -->
			</view>
			<view class="section">
				<!-- order info begin -->
				<list-cell :hover="false" padding="50rpx 30rpx">
					<view class="w-100 d-flex flex-column">
						<view class="pay-cell">
							<view>下单时间</view>
							<view class="font-weight-bold">{{detail.create_time}}</view>
						</view>
						<!-- 								<view class="pay-cell">
									<view>下单门店</view>
									<view class="font-weight-bold">{{ detail.store.name }}</view>
								</view> -->
						<view class="pay-cell">
							<view>支付方式</view>
							<view class="font-weight-bold">{{ detail.pay_type.text }}</view>
						</view>
						<view class="pay-cell">
							<view>订单号</view>
							<view class="font-weight-bold">{{ detail.order_no }}</view>
						</view>
					</view>
				</list-cell>
				<!-- order info end -->
			</view>
			<!-- order other info begin -->
			<list-cell :hover="false" padding="50rpx 30rpx 20rpx" last>
				<view class="w-100 d-flex flex-column">
					<view class="pay-cell">
						<view>取单号</view>
						<view class="font-weight-bold">{{ detail.meal_code }}</view>
					</view>
					<view class="pay-cell" v-if="detail.delivery_type.value==20">
						<view>取餐时间</view>
						<view class="font-weight-bold">{{ detail.mealtime }}</view>
					</view>
					<view class="pay-cell">
						<view>享用方式</view>
						<view class="font-weight-bold">{{detail.delivery_type.text}}</view>
					</view>
					<view class="pay-cell">
						<view>备注</view>
						<view class="font-weight-bold">{{ detail.buyer_remark }}</view>
					</view>
				</view>
			</list-cell>
			<!-- order other info end -->
		</view>
	</view>
</template>

<script>
	import Popup from '@/components/uni-popup.vue';
	import {
		pay
	} from '@/common/pay.js';
	export default {
		data() {
			return {
				/*是否加载完成*/
				loadding: true,
				indicatorDots: true,
				autoplay: true,
				interval: 2000,
				duration: 500,
				/*是否显示支付类别弹窗*/
				isPayPopup: false,
				/*订单id*/
				order_id: 0,
				/*订单详情*/
				detail: {
					order_status: [],
					address: {
						region: []
					},
					product: [],
					pay_type: [],
					delivery_type: [],
					pay_status: []
				},
				extractStore: {},
				/*是否显示拼团*/
				is_fightgroup: false,
				/*是否显示支付宝支付，只有在h5，非微信内打开才显示*/
				showAlipay: false
			};
		},
		components: {
			Popup
		},
		onLoad(e) {
			this.order_id = e.order_id;
		},
		mounted() {
			uni.showLoading({
				title: '加载中'
			});
			/*获取订单详情*/
			this.getData();
		},
		methods: {
			/*获取数据*/
			getData() {
				let self = this;
				let order_id = self.order_id;
				self._get(
					'user.order/detail', {
						order_id: order_id
					},
					function(res) {
						self.detail = res.data.order;
						self.extractStore = res.data.order.extractStore;
						//#ifdef H5
						if (!self.isWeixin() && res.data.h5_alipay) {
							self.showAlipay = true;
						}
						//#endif
						self.loadding = false;
						uni.hideLoading();
					}
				);
			},
			/*显示支付方式*/
			hidePopupFunc() {
				this.isPayPopup = false;
			},

			/*取消订单*/
			cancelOrder(e) {
				let self = this;
				let order_id = e;
				wx.showModal({
					title: '提示',
					content: '您确定要取消当前订单吗?',
					success: function(o) {
						if (o.confirm) {
							uni.showLoading({
								title: '正在处理'
							});
							self._get(
								'user.order/cancel', {
									order_id: order_id
								},
								function(res) {
									uni.hideLoading();
									uni.showToast({
										title: '操作成功',
										duration: 2000,
										icon: 'success'
									});
									self.getData();
								}
							);
						}
					}
				});
			},

			/*确认收货*/
			orderReceipt(order_id) {
				let self = this;
				wx.showModal({
					title: '提示',
					content: '您确定要收货吗?',
					success: function(o) {
						if (o.confirm) {
							uni.showLoading({
								title: '正在处理'
							});
							self._post(
								'user.order/receipt', {
									order_id: order_id
								},
								function(res) {
									uni.hideLoading();
									uni.showToast({
										title: res.msg,
										duration: 2000,
										icon: 'success'
									});
									self.getData();
								}
							);
						}
					}
				});
			},
			/*查看物流*/
			gotoExpress(order_id) {
				uni.navigateTo({
					url: '/pages/order/express/express?order_id=' + order_id
				});
			},
			/*申请售后*/
			onApplyRefund(e) {
				uni.navigateTo({
					url: '/pages/order/refund/apply/apply?order_product_id=' + e
				});
			},

			/*去支付*/
			payTypeFunc(payType) {
				let self = this;
				let order_id = self.order_id;
				self.isPayPopup = false;
				uni.showLoading({
					title: '加载中'
				});
				self._post(
					'user.order/pay', {
						payType: payType,
						order_id: order_id,
						pay_source: self.getPlatform()
					},
					function(res) {
						uni.hideLoading();
						pay(res, self);
					}
				);
			},

			/*支付方式选择*/
			onPayOrder(orderId) {
				let self = this;
				self.isPayPopup = true;
				self.order_id = orderId;
			}
		}
	};
</script>

<style lang="scss" scoped>
	/* #ifdef H5 */
	page {
		min-height: 100%;
		background-color: $bg-color;
	}

	/* #endif */
	.order-box {
		padding: 20rpx;
		/* #ifdef H5 */
		margin-bottom: 100rpx;
		/* #endif */
	}

	.drinks-img {
		width: 260rpx;
		height: 260rpx;
	}

	.tips {
		margin: 60rpx 0 80rpx;
		line-height: 48rpx;
	}

	.drink-btn {
		width: 320rpx;
		border-radius: 50rem !important;
		margin-bottom: 40rpx;
		font-size: $font-size-base;
		line-height: 3.0;
	}

	@mixin arch {
		content: "";
		position: absolute;
		background-color: $bg-color;
		width: 30rpx;
		height: 30rpx;
		bottom: -15rpx;
		z-index: 10;
		border-radius: 100%;
	}

	.section {
		position: relative;

		&::before {
			@include arch;
			left: -15rpx;
		}

		&::after {
			@include arch;
			right: -15rpx;
		}
	}

	.pay-cell {
		width: 100%;
		display: flex;
		align-items: center;
		justify-content: space-between;
		font-size: $font-size-base;
		color: $text-color-base;
		margin-bottom: 40rpx;

		&:nth-last-child(1) {
			margin-bottom: 0;
		}
	}

	.sort-num {
		font-size: 64rpx;
		font-weight: bold;
		color: $text-color-base;
		line-height: 2;
	}

	.steps__img-column {
		display: flex;
		margin: 30rpx 0;

		.steps__img-column-item {
			flex: 1;
			display: flex;
			align-items: center;
			justify-content: center;

			image {
				width: 80rpx;
				height: 80rpx;
			}
		}
	}

	.steps__text-column {
		display: flex;
		margin-bottom: 40rpx;

		.steps__text-column-item {
			flex: 1;
			display: inline-flex;
			display: flex;
			align-items: center;
			justify-content: center;
			font-size: $font-size-base;
			color: $text-color-assist;

			&.active {
				color: $text-color-base;
				font-weight: bold;

				.steps__column-item-line {
					background-color: $text-color-base;
				}
			}

			.steps__column-item-line {
				flex: 1;
				height: 2rpx;
				background-color: #919293;
				transform: scaleY(0.5);
			}

			.steps__text-column-item-text {
				margin: 0 8px;
			}
		}
	}
	.pay_btn{
		border: 1rpx solid #f5a654;
		color: #f5a654;
		padding: 10rpx 20rpx;
		border-radius: 20rpx;
	}
</style>
